#pragma once

#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <interactive_markers/interactive_marker_server.hpp>
#include <rclcpp/rclcpp.hpp>
#include <QColor>
#include <QVector3D>
#include <QJsonObject>


using interactive_markers::InteractiveMarkerServer;

namespace rviz_custom_plugins
{

namespace utils
{

class InteractiveMarkerThread : public QThread {
    Q_OBJECT

public:
    explicit InteractiveMarkerThread(QObject *parent = nullptr);
    ~InteractiveMarkerThread();

    std::size_t size() const;
    void insert(const visualization_msgs::msg::InteractiveMarker & marker);
    bool erase(const std::string & name);
    bool get(const std::string & name, visualization_msgs::msg::InteractiveMarker & intMarker) const;

    void setActive(bool active);
    bool getActive() const;

signals:
    void interactiveMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr callback);
    void activeStatusChanged(bool active);

protected:
    void run() override;

private:
    std::shared_ptr<rclcpp::Node> rosNode;
    std::shared_ptr<InteractiveMarkerServer> server;
	std::map<std::string, visualization_msgs::msg::InteractiveMarker::SharedPtr> markerMap;
    QMutex mutex;
	InteractiveMarkerServer::FeedbackCallback feedbackFunc;
    bool isActive;

	void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);

    void markerEventFeedback(const visualization_msgs::msg::InteractiveMarker& intMarker, std::string event);

};


}

}
